#ifndef UTILS_H
#define UTILS_H

#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif 

#include <time.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

// error 
struct http_error_code{
    const char *token;
    int  code;
} ;
const char* get_error_status(int err);


// time
float NTP_time(time_t t);
void  GetCurrentTime(char* buf);
void  get_localtime_str(char* buf);
char* get_current_time();
int   get_UTC_time(struct tm *t,char *b);

// net
int   setnonblock(int fd);
int   get_ipaddr(int fd,char* buf,int bufsize);

int   is_supported_url(char *p);
int   parse_url(const char *url,char *server, size_t, unsigned short *port, char *file_name, size_t);

// system
int   print_cpu_affinity();
int   set_cpu_affinity(uint32_t cpu_affinity);
int	  get_token_disk_path(char *szpath, int pathlen, const char *tokename);

extern const int endian;
#define is_big_endian() (0x12 == *(char*)&endian)
unsigned short j_htons (unsigned short x);



#ifndef min
#define min(x,y) ((x) < (y) ? (x) : (y))
#endif
#ifndef max
#define max(x,y) ((x) > (y) ? (x) : (y))
#endif



#ifdef __cplusplus
}
#endif

#endif //defined(UTILS_H)
